package com.rongc.client.freight.business.supply.view.fragment;

import android.view.View;
import android.widget.TextView;

import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.R;
import com.rongc.client.freight.UniApplication;
import com.rongc.client.freight.base.BaseFragment;
import com.rongc.client.freight.base.model.BaseDic;
import com.rongc.client.freight.business.carrier.model.ConveyanceBean;
import com.rongc.client.freight.business.carrier.model.ConveyanceDic;
import com.rongc.client.freight.business.supply.model.SupplyBean;
import com.rongc.client.freight.business.supply.model.SupplyDic;
import com.rongc.client.freight.business.waybill.model.WayBillBean;
import com.rongc.client.freight.business.waybill.model.WayBillDetailBean;

import butterknife.Bind;

/**
 * Created by ccqx on 2017/8/9.
 */

public class SupplyFragment extends BaseFragment {

    @Bind(R.id.tv_departure)
    TextView mTvDeparture;
    @Bind(R.id.tv_total)
    TextView mTvTotal;
    @Bind(R.id.tv_date)
    TextView mTvDate;
    @Bind(R.id.tv_model)
    TextView mTvModel;
    @Bind(R.id.tv_status)
    TextView mTvStatus;
    @Bind(R.id.tv_jia)
    TextView mTvJia;

    public void setListener(View.OnClickListener listener){
        mTvStatus.setOnClickListener(listener);
        mTvJia.setOnClickListener(listener);


    }

    public void setData(ConveyanceBean conveyanceBean){
        mTvDeparture.setText(conveyanceBean.getStartPlace() + " — " +conveyanceBean.getEndPlace());
        mTvDate.setText(conveyanceBean.getLoadTime());
        mTvModel.setText(StringUtils.getNewModel(getActivity(),conveyanceBean.getCarLength(),conveyanceBean.getCarLoad(),conveyanceBean.getDulk(),conveyanceBean.getCarModels()));

        mTvStatus.setEnabled(true);
        mTvStatus.setText("取消接单");
        mTvTotal.setVisibility(View.GONE);
        mTvJia.setVisibility(View.GONE);

    }

    public void setData(SupplyBean supplyBean){
        mTvDeparture.setText(supplyBean.getStartPlace() + " — " +supplyBean.getEndPlace());
        mTvTotal.setText(String.format(getResources().getString(R.string.supply_waybill_total),supplyBean.getFreightByType()));
        mTvDate.setText(supplyBean.getLoadTime());
        mTvModel.setText(StringUtils.getNewModel(getActivity(),supplyBean.getCarLength(),supplyBean.getWeights(),supplyBean.getDilk(),supplyBean.getCarModels()));

        mTvStatus.setText("取消派单");
        mTvStatus.setEnabled(true);
    }

    public void setData(WayBillBean bean){
        mTvDeparture.setText(bean.getStartplace() + " — " +bean.getEndplace());

        mTvDate.setText(bean.getLoadtime());
        mTvModel.setText(StringUtils.getNewModel(getActivity(),bean.getCarlength(),bean.getWeights(),bean.getDulk(),bean.getCarmodels()));

        switch (UniApplication.getInstance().getType()) {
            case BaseDic.IdentityType.OWNER_TYPE:
                mTvStatus.setText(SupplyDic.getStatusStr(StringUtils.parseInt(bean.getWaystate())));
                break;
            case BaseDic.IdentityType.DRIVING_TYPE:
                mTvStatus.setText(ConveyanceDic.getStatusStr(StringUtils.parseInt(bean.getWaystate())));
                break;
        }

        if(SupplyDic.getStatusEnable(StringUtils.parseInt(bean.getWaystate()))){
            mTvTotal.setVisibility(View.VISIBLE);
            mTvStatus.setEnabled(true);
        }else{
            mTvTotal.setVisibility(View.INVISIBLE);
            mTvStatus.setEnabled(false);
        }

    }

    public void setData(WayBillDetailBean bean){
        setData((WayBillBean)bean);
        mTvTotal.setText(String.format(getActivity().getResources().getString(R.string.supply_waybill_total),bean.getCostByType()));
    }


    @Override
    public int getLayoutId() {
        return R.layout.include_supply;
    }

    @Override
    public void initView() {

    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {

    }
}
